from machine import Pin,SoftI2C,ADC,PWM
from lib.sh1106 import SH1106, SH1106_I2C
from setting import *
import time
import utime
import random

class PowerScreen:
    #生命值的绘制
    live_list=[0x30,0x4C,0x42,0x21,0x21,0x42,0x4C,0x30]
    #绘制恐龙
    dinosaur=[0x03,0x01,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x7F,0xFF,0x8F,0xAF,0x8D,0xF9,0x78,
    0xC0,0xE0,0xF0,0x78,0x7F,0xFD,0xF0,0xFC,0xFF,0xF9,0xF0,0xE0,0xC0,0x00,0x80,0x00]

    def __init__(self, sclPin, sdaPin, freq1, width, height):
        self.i2c = SoftI2C(scl=Pin(sclPin), sda=Pin(sdaPin), freq=freq1)
        self.oled = SH1106_I2C(width, height, self.i2c, None, 0x3c)

    def initScreen(self):
        #初始化屏幕
        self.oled.fill(0)
        self.oled.p8(self.live_list,0,0)
        self.oled.p8(self.live_list,9,0)
        self.oled.p8(self.live_list,18,0)
        self.oled.text('0',120,0)
        self.oled.p16(self.dinosaur,0,48)
        self.oled.rect(117,53,10,10,True)
        self.oled.show()

